package com.dfbz.demo01_卖票案例;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo09_线程的加入 {
    public static void main(String[] args) {
        //创建线程1
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println("线程1:" + i);
                }
            }
        });


        //创建线程2
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println("线程2:" + i);
                    if (i == 500) {
                        try {
                            //当i等于500的时候,让t1线程加入执行,直至执行完毕
                            t1.join();
                            //当i等于500的时候,让t1线程加入执行,执行10毫秒之后交出执行权
//                            t1.join(10);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                }
            }
        });

        t1.start();
        t2.start();
    }
}
